package com.example.mediaplayerdemo.videoplay.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

import com.example.mediaplayerdemo.R;

public class VideoPlayActivity extends AppCompatActivity {
    private VideoView videoView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_play);
//        强制横屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        videoView = findViewById(R.id.videoView);
//        网络视频访问
//        String uri = "https://vd2.bdstatic.com/mda-mh44p4ahr71hhp1q/1080p/cae_h264/1628134869373171596/mda-mh44p4ahr71hhp1q.mp4?v_from_s=hkapp-haokan-hnb&auth_key=1628148042-0-0-22e75efd28f19062960121359ce1adb2&bcevod_channel=searchbox_feed&pd=1&pt=3&abtest=3000186_1";
//        videoView.setVideoURI(Uri.parse(uri));
//        本地资源访问
        videoView.setVideoURI(Uri.parse("android.resource://"+ getPackageName()+"/" + R.raw.as4));

//        设置媒体控制器
        MediaController mediaController = new MediaController(this);
        mediaController.setMediaPlayer(videoView);
        videoView.setMediaController(mediaController);
//        为控件设置焦点
        videoView.requestFocus();
//        开始播放
        videoView.start();
    }
}